package day1_12.other;
// 双色球号码随机生成器,输入号码匹配中奖情况
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class DoubleColorBall2 {

    public static void main(String[] args) {
        System.out.println("当前中奖号码为:");
        System.out.println("---------------------");
        for (int j = 0; j < 5; j++) {
            int [] arr = createNumber();
            for (int i = 0; i < arr.length; i++) {
                System.out.print(arr[i] + " ");
            }
            System.out.println(" ");
        }
        System.out.println();
        System.out.println("---------------------");
    }
//    创建号码的方法
    public static int[] createNumber(){
        int [] arr = new int[7];
        Random random = new Random();
        for (int i = 0; i < 6; ) {
//            红色球号码范围1-33
            int redNum = random.nextInt(33) + 1;
            boolean flag = contains(arr,redNum);
            if(!flag){
                arr[i] = redNum;
                i++;
            }
        }
        int blueNum = random.nextInt(16) + 1;
        arr[arr.length-1] = blueNum;
        return arr;
    }
//    判断生成数字是否已经在数组中
    public static boolean contains(int[] arr, int number) {
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] == number) {
                return true;
            }
        }
        return false;
    }
}
